package com.plwf.lake.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.plwf.lake.entity.Period;
import com.plwf.lake.service.PeriodService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 *
 */
@RestController
@RequestMapping("/period")
public class PeriodCtrl {
    @Resource
    private PeriodService service;

    @RequestMapping("/query/{stuId}/{subId}")
    public Period query(@PathVariable("stuId") Integer stuId,@PathVariable("subId")Integer subId){
        Period bean = new Period();
        bean.setStuId((Integer)stuId);
        bean.setSubId((Integer)subId);
        return this.service.query(bean);
    }

    @RequestMapping("/save")
    public Boolean save(HttpServletRequest request){
        String id = request.getParameter("id");
        String stuId = request.getParameter("stuId");
        String subId = request.getParameter("subId");
        String hour = request.getParameter("hour");
        Map<String,Object> map = new HashMap<>();
        if(id!=null && !id.equals("")){
            map.put("id",Integer.parseInt(id));
        }else{
            map.put("id",null);
        }
        if(stuId!=null && !stuId.equals("")){
            map.put("stuId",Integer.parseInt(stuId));
        }else{
            map.put("stuId",null);
        }
        if(subId!=null && !subId.equals("")){
            map.put("subId",Integer.parseInt(subId));
        }else{
            map.put("subId",null);
        }
        if(hour!=null && !hour.equals("")){
            map.put("hour",Integer.parseInt(hour));
        }else{
            map.put("hour",null);
        }
        return service.save(map);

    }

}
